//
//  MenuViewController.m
//  WXWeiBo
//
//  Created by 朱思明 on 15/9/14.
//  Copyright (c) 2015年 朱思明. All rights reserved.
//
#import "UIViewController+MMDrawerController.h"
#import "MenuViewController.h"
#import "MainTabBarController.h"
#import "LitterLLeftViewController.h"
#import "MMExampleDrawerVisualStateManager.h"
#import "LockController.h"
@interface MenuViewController ()

@end

@implementation MenuViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor clearColor];
    // Do any additional setup after loading the view.
//         MainTabBarController *tabC =(MainTabBarController *)[[MainTabBarController alloc] init];
//       LitterLLeftViewController *leftVC = [[LitterLLeftViewController alloc]init];
//        UINavigationController *leftNvaVC = [[UINavigationController alloc]initWithRootViewController:leftVC];

    // 01 获取左侧视图控制器
       LitterLLeftViewController *leftVC = [[LitterLLeftViewController alloc]init];
               UINavigationController *leftNvaVC = [[UINavigationController alloc]initWithRootViewController:leftVC];

    self.leftDrawerViewController = leftVC;
        

//     02 获取中间视图控制器
         MainTabBarController *tabC =(MainTabBarController *)[[MainTabBarController alloc] init];
    self.centerViewController = tabC;
    // 03 获取右侧视图控制器
    
    self.rightDrawerViewController = nil;
    // 04 设置左右视图控制器显示的宽度

 self.openDrawerGestureModeMask = MMOpenDrawerGestureModeAll;
    self.closeDrawerGestureModeMask = MMCloseDrawerGestureModeAll;
    // 06 配置动画效果
    [self setDrawerVisualStateBlock:^(MMDrawerController *drawerController, MMDrawerSide drawerSide, CGFloat percentVisible) {
        // 设置动画效果
        MMDrawerControllerDrawerVisualStateBlock block = [[MMExampleDrawerVisualStateManager sharedManager] drawerVisualStateBlockForDrawerSide:drawerSide];
        if (block != nil) {
            block(drawerController,drawerSide,percentVisible);
        }
    }];
        self.maximumLeftDrawerWidth = 250;
    self.maximumRightDrawerWidth = 60;
    // 设置动画类型
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    NSDictionary *dic = [userDefaults objectForKey:kDrawAnimateType];
    NSInteger leftDrawType = [dic[kDrawLeftType] integerValue];
    [MMExampleDrawerVisualStateManager sharedManager].leftDrawerAnimationType = leftDrawType;
    [MMExampleDrawerVisualStateManager sharedManager].rightDrawerAnimationType = leftDrawType;
    
     [_drawerController setGestureShouldRecognizeTouchBlock:^BOOL(MMDrawerController *drawerController, UIGestureRecognizer *gesture, UITouch *touch) {

        BOOL shouldRecognizeTouch = NO;

        if(drawerController.openSide == MMDrawerSideNone &&

           [gesture isKindOfClass:[UIPanGestureRecognizer class]]){

            UINavigationController *nav = (UINavigationController *)drawerController.centerViewController;

            if([nav.topViewController isKindOfClass:[LockController class]]){//判断哪个控制器可以滑到抽屉

                shouldRecognizeTouch = NO;//返回yes表示可以滑动到左右侧抽屉

            }else{

                shouldRecognizeTouch = YES;

            }

  /*UIView * customView = [nav.topViewController view];

            CGPoint location = [touch locationInView:customView];//返回触摸点在view的坐标

            shouldRecognizeTouch = (CGRectContainsPoint(customView.bounds, location));//意思就是当point的位置在rect里面就返回yes，否则返回no*/

            NSLog(@"shouldRecognizeTouch==%d",shouldRecognizeTouch);

        }

        return shouldRecognizeTouch;

     }];





    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
